package com.dong.springboot.rabbitmq.work;

import com.dong.springboot.rabbitmq.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.QueueingConsumer;

import java.io.IOException;

/**
 * @author: dong peng
 * @date: 2019/2/20 10:58
 * @description:  work模式
 * 轮询分发
 */

public class Send2Work {

    public static void main(String[] args) throws IOException, InterruptedException {

        String QUEUE_NAME = "queue1";

        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);

        for(int i = 0; i < 100; i++) {
            String str = "这是第" + i + "say hai";
            channel.basicPublish("", QUEUE_NAME, null, str.getBytes());

            System.out.println("生产者: " + str);
            Thread.sleep(500);
        }

        channel.close();
        connection.close();

    }
}
